import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TCPServer {
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(8888);
            System.out.println("启动服务器，打开监听端口 8888");
            Socket socket = serverSocket.accept();
            System.out.println("接受客户端连接，开始进行数据传输");

            InputStream inputStream = socket.getInputStream();
            OutputStream outputStream = socket.getOutputStream();

            byte[] input = new byte[1024];
            byte[] output = {'H','e','l','l','o',',','w','o','r','l','d','!'};
            outputStream.write(output);

            inputStream.close();
            outputStream.close();
            socket.close();
            serverSocket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
